<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java web," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="说明：JavaTools配置使用，包括jdbc、分词工具、quartz定时等。">
<meta name="keywords" content="Java web">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaTools">
<meta property="og:url" content="http://bebetter.site/2017/01/12/Software/Java Web/JavaTools/index.html">
<meta property="og:site_name" content="gatewayzy">
<meta property="og:description" content="说明：JavaTools配置使用，包括jdbc、分词工具、quartz定时等。">
<meta property="og:updated_time" content="2017-01-12T05:58:56.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaTools">
<meta name="twitter:description" content="说明：JavaTools配置使用，包括jdbc、分词工具、quartz定时等。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://bebetter.site/2017/01/12/Software/Java Web/JavaTools/"/>

  <title> JavaTools | gatewayzy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">gatewayzy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">blog of gatewayzy</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                JavaTools
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-01-12T13:58:10+08:00" content="2017-01-12">
              2017-01-12
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Softwares/" itemprop="url" rel="index">
                    <span itemprop="name">Softwares</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>说明：</strong>JavaTools配置使用，包括jdbc、分词工具、quartz定时等。<br><a id="more"></a></p>
<hr>
<p>参考文章：</p>
<h2 id="Ajax跨域请求允许"><a href="#Ajax跨域请求允许" class="headerlink" title="Ajax跨域请求允许"></a>Ajax跨域请求允许</h2><hr>
<p>Ajax在请求本项目之外的网站时，产生跨域请求，所有网站默认是拒绝跨域请求的。</p>
<h3 id="修改被请求网站响应设置"><a href="#修改被请求网站响应设置" class="headerlink" title="修改被请求网站响应设置"></a>修改被请求网站响应设置</h3><ul>
<li>只有前端访问后端存在跨域问题，应考虑通过后端进行httpclient等方式请求再封装避免跨域问题。</li>
<li>通过设置请求网站的响应允许跨域请求。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">@RequestMapping(value=&quot;/posttrack&quot;,method = RequestMethod.POST)</div><div class="line">public void posttrack(@RequestParam String data,HttpServletRequest request,HttpServletResponse response) &#123;</div><div class="line">	response.addHeader(&quot;Access-Control-Allow-Origin&quot;,&quot;*&quot;);</div><div class="line">	return;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="中文分词工具"><a href="#中文分词工具" class="headerlink" title="中文分词工具"></a>中文分词工具</h2><hr>
<h3 id="IKAnalyzer与Lucene"><a href="#IKAnalyzer与Lucene" class="headerlink" title="IKAnalyzer与Lucene"></a>IKAnalyzer与Lucene</h3><h3 id="IKAnalyzer特点"><a href="#IKAnalyzer特点" class="headerlink" title="IKAnalyzer特点"></a>IKAnalyzer特点</h3><ul>
<li>IKAnalyzer支持中文分词，支持拓展词典和停用词。</li>
<li>Lucene在全文上建立索引文件，通过java等方式进行查询。中文中经常使用IKAnalyzer作为分词工具，将全文进行分词后建立索引。</li>
</ul>
<h3 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h3><ul>
<li>后缀名.dic的词典文件，必须使用文档里所说的无BOM的UTF-8编码保存的文件。如果不确定什么是无BOM的UTF-8编码，最简单的方式就是用Notepad++编辑器打开，Encoding-&gt;选择 Encoding in UTF-8 without BOM，然后保存。</li>
<li>项目preferences里编码选择utf8。</li>
<li>词典和IKAnalyzer.cfg.xml配置文件的路径问题。IKAnalyzer.cfg.xml必须在src根目录下。词典可以任意放，但是在IKAnalyzer.cfg.xml里要配置对。如下：我的两个词典文件my.dic 和 mine.dic 放在src下的com.org.config包下，注意com前面一定不要加/，否则是绝对路径找不到。</li>
<li>注意：maven项目中IKAnalyzer.cfg.xml放在resources下即可，里面路径以resources为/。</li>
</ul>
<h3 id="配置demo"><a href="#配置demo" class="headerlink" title="配置demo"></a>配置demo</h3><ul>
<li>IKAnalyzer.cfg.xml（IK是3.2.8）</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</div><div class="line">&lt;!DOCTYPE properties SYSTEM &quot;http://java.sun.com/dtd/properties.dtd&quot;&gt;  </div><div class="line">&lt;properties&gt;  </div><div class="line">    &lt;comment&gt;IK Analyzer 扩展配置&lt;/comment&gt;</div><div class="line">    &lt;!-- 用户可以在这里配置自己的扩展字典 --&gt;</div><div class="line">     &lt;entry key=&quot;ext_dict&quot;&gt;/dic/ext_dic.dic&lt;/entry&gt; </div><div class="line">     &lt;!-- 用户可以在这里配置自己的扩展停止词字典    --&gt;</div><div class="line">    &lt;entry key=&quot;ext_stopwords&quot;&gt;/dic/stopwords.dic&lt;/entry&gt; </div><div class="line">&lt;/properties&gt;</div></pre></td></tr></table></figure>
<ul>
<li>MyLucene.java（Lucene是3.5.0）</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div></pre></td><td class="code"><pre><div class="line">package lucene;</div><div class="line">import java.io.IOException;</div><div class="line">import java.io.StringReader;</div><div class="line">import org.apache.lucene.analysis.Analyzer;</div><div class="line">import org.apache.lucene.analysis.TokenStream;</div><div class="line">import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;</div><div class="line">import org.apache.lucene.document.Document;</div><div class="line">import org.apache.lucene.document.Field;</div><div class="line">import org.apache.lucene.document.Field.Index;</div><div class="line">import org.apache.lucene.document.Field.Store;</div><div class="line">import org.apache.lucene.index.IndexReader;</div><div class="line">import org.apache.lucene.index.IndexWriter;</div><div class="line">import org.apache.lucene.index.IndexWriterConfig;</div><div class="line">import org.apache.lucene.index.IndexWriterConfig.OpenMode;</div><div class="line">import org.apache.lucene.queryParser.QueryParser;</div><div class="line">import org.apache.lucene.search.IndexSearcher;</div><div class="line">import org.apache.lucene.search.Query;</div><div class="line">import org.apache.lucene.search.ScoreDoc;</div><div class="line">import org.apache.lucene.search.TopDocs;</div><div class="line">import org.apache.lucene.store.Directory;</div><div class="line">import org.apache.lucene.store.FSDirectory;</div><div class="line">import org.apache.lucene.store.RAMDirectory;</div><div class="line">import org.apache.lucene.util.Version;</div><div class="line">import org.wltea.analyzer.lucene.IKAnalyzer;</div><div class="line"></div><div class="line">public class MyLucene &#123;</div><div class="line">	 public static void main(String[] args) &#123;  </div><div class="line">		// 使用Lucene分词  </div><div class="line">		//Lucene Document的域名</div><div class="line">		String fieldName = &quot;text&quot;;</div><div class="line">		//检索内容</div><div class="line">		String text = &quot;据说WWDC要推出iPhone6要出了？与iPhone5s土豪金相比怎样呢？&quot;;</div><div class="line">		//实例化IKAnalyzer分词器</div><div class="line">		Analyzer analyzer = new IKAnalyzer();</div><div class="line"></div><div class="line">		Directory directory = null;</div><div class="line">		IndexWriter iwriter = null;</div><div class="line">		IndexReader ireader = null;</div><div class="line">		IndexSearcher isearcher = null;</div><div class="line">		try &#123;</div><div class="line">		    //建立内存索引对象</div><div class="line">		    directory = new RAMDirectory();     </div><div class="line"></div><div class="line">		    //配置IndexWriterConfig</div><div class="line">		    IndexWriterConfig iwConfig = new IndexWriterConfig(Version.LUCENE_34 , analyzer);</div><div class="line">		    iwConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);</div><div class="line">		    iwriter = new IndexWriter(directory , iwConfig);</div><div class="line">		    //写入索引</div><div class="line">		    Document doc = new Document();</div><div class="line">		    doc.add(new Field(&quot;ID&quot;, &quot;10000&quot;, Field.Store.YES, Field.Index.NOT_ANALYZED));</div><div class="line">		    doc.add(new Field(fieldName, text, Field.Store.YES, Field.Index.ANALYZED));</div><div class="line">		    iwriter.addDocument(doc);</div><div class="line">		    iwriter.close();</div><div class="line"></div><div class="line">		    //搜索过程**********************************</div><div class="line">		    //实例化搜索器   </div><div class="line">		    ireader = IndexReader.open(directory);</div><div class="line">		    isearcher = new IndexSearcher(ireader);            </div><div class="line"></div><div class="line">		    String keyword = &quot;iPhone5s土豪金&quot;;            </div><div class="line">		    //使用QueryParser查询分析器构造Query对象</div><div class="line">		    QueryParser qp = new QueryParser(Version.LUCENE_34, fieldName, analyzer);</div><div class="line">		    qp.setDefaultOperator(QueryParser.AND_OPERATOR);</div><div class="line">		    Query query = qp.parse(keyword);</div><div class="line">		    System.out.println(&quot;Query = &quot; + query);</div><div class="line"></div><div class="line">		    //搜索相似度最高的5条记录</div><div class="line">		    TopDocs topDocs = isearcher.search(query , 5);</div><div class="line">		    System.out.println(&quot;命中：&quot; + topDocs.totalHits);</div><div class="line">		    //输出结果</div><div class="line">		    ScoreDoc[] scoreDocs = topDocs.scoreDocs;</div><div class="line">		    for (int i = 0; i &lt; topDocs.totalHits; i++)&#123;</div><div class="line">		        Document targetDoc = isearcher.doc(scoreDocs[i].doc);</div><div class="line">		        System.out.println(&quot;内容：&quot; + targetDoc.toString());</div><div class="line">		    &#125;</div><div class="line"></div><div class="line">		&#125; catch (Exception e) &#123;</div><div class="line">		    e.printStackTrace();</div><div class="line">		&#125; finally&#123;</div><div class="line">		    if(ireader != null)&#123;</div><div class="line">		        try &#123;</div><div class="line">		            ireader.close();</div><div class="line">		        &#125; catch (Exception e) &#123;</div><div class="line">		            e.printStackTrace();</div><div class="line">		        &#125;</div><div class="line">		    &#125;</div><div class="line">		    if(directory != null)&#123;</div><div class="line">		        try &#123;</div><div class="line">		            directory.close();</div><div class="line">		        &#125; catch (IOException e) &#123;</div><div class="line">		            e.printStackTrace();</div><div class="line">		        &#125;</div><div class="line">		    &#125;</div><div class="line">		&#125;</div><div class="line">	 &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="Quartz-定时任务"><a href="#Quartz-定时任务" class="headerlink" title="Quartz 定时任务"></a>Quartz 定时任务</h2><hr>
<ul>
<li>引入Quartz版本</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.quartz-scheduler&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;quartz&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;1.7.3&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div></pre></td></tr></table></figure>
<ul>
<li>测试任务：任务是普通类。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">package quartz;</div><div class="line">import java.text.SimpleDateFormat;</div><div class="line">import java.util.Date;</div><div class="line"></div><div class="line">import org.quartz.Job;</div><div class="line">import org.quartz.JobExecutionContext;</div><div class="line">import org.quartz.JobExecutionException;</div><div class="line"></div><div class="line">public class TestJob implements Job &#123;</div><div class="line">	SimpleDateFormat DateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd HH:mm:ss&quot;);</div><div class="line">	Date d = new Date();</div><div class="line">	String returnstr = DateFormat.format(d);</div><div class="line"></div><div class="line">	public void execute(JobExecutionContext arg0) throws JobExecutionException &#123;</div><div class="line">		System.out.println(returnstr + &quot; a testJob is running★★★★★★★★★★★&quot;);</div><div class="line">	&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li>任务管理工具类</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div></pre></td><td class="code"><pre><div class="line">package quartz;</div><div class="line"></div><div class="line">import java.text.ParseException;</div><div class="line">import org.quartz.CronTrigger;</div><div class="line">import org.quartz.Job;</div><div class="line">import org.quartz.JobDetail;</div><div class="line">import org.quartz.Scheduler;</div><div class="line">import org.quartz.SchedulerException;</div><div class="line">import org.quartz.SchedulerFactory;</div><div class="line">import org.quartz.Trigger;</div><div class="line">import org.quartz.impl.StdSchedulerFactory;</div><div class="line"></div><div class="line">/**</div><div class="line"> * @Title:Quartz管理类</div><div class="line"> * </div><div class="line"> */</div><div class="line">public class QuartzManager &#123;</div><div class="line">	private static SchedulerFactory sf = new StdSchedulerFactory();</div><div class="line">	private static String JOB_GROUP_NAME = &quot;group1&quot;;</div><div class="line">	private static String TRIGGER_GROUP_NAME = &quot;trigger1&quot;;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 添加一个定时任务，使用默认的任务组名，触发器名，触发器组名</div><div class="line">	 */</div><div class="line">	public static void addJob(String jobName, Job job, String time) throws SchedulerException, ParseException &#123;</div><div class="line">		Scheduler sched = sf.getScheduler();</div><div class="line">		JobDetail jobDetail = new JobDetail(jobName, JOB_GROUP_NAME, job.getClass());// 任务名，任务组，任务执行类</div><div class="line">		// 触发器</div><div class="line">		CronTrigger trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);// 触发器名,触发器组</div><div class="line">		trigger.setCronExpression(time);// 触发器时间设定</div><div class="line">		sched.scheduleJob(jobDetail, trigger);</div><div class="line">		// 启动</div><div class="line">		if (!sched.isShutdown())</div><div class="line">			sched.start();</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 添加一个定时任务</div><div class="line">	 */</div><div class="line">	public static void addJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName, Job job,</div><div class="line">			String time) throws SchedulerException, ParseException &#123;</div><div class="line">		Scheduler sched = sf.getScheduler();</div><div class="line">		JobDetail jobDetail = new JobDetail(jobName, jobGroupName, job.getClass());// 任务名，任务组，任务执行类</div><div class="line">		// 触发器</div><div class="line">		CronTrigger trigger = new CronTrigger(triggerName, triggerGroupName);// 触发器名,触发器组</div><div class="line">		trigger.setCronExpression(time);// 触发器时间设定</div><div class="line">		sched.scheduleJob(jobDetail, trigger);</div><div class="line">		if (!sched.isShutdown())</div><div class="line">			sched.start();</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 修改一个任务的触发时间(使用默认的任务组名，触发器名，触发器组名)</div><div class="line">	 */</div><div class="line">	public static void modifyJobTime(String jobName, String time) throws SchedulerException, ParseException &#123;</div><div class="line">		Scheduler sched = sf.getScheduler();</div><div class="line">		Trigger trigger = sched.getTrigger(jobName, TRIGGER_GROUP_NAME);</div><div class="line">		if (trigger != null) &#123;</div><div class="line">			CronTrigger ct = (CronTrigger) trigger;</div><div class="line">			ct.setCronExpression(time);</div><div class="line">			sched.resumeTrigger(jobName, TRIGGER_GROUP_NAME);</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 修改一个任务的触发时间</div><div class="line">	 */</div><div class="line">	public static void modifyJobTime(String triggerName, String triggerGroupName, String time)</div><div class="line">			throws SchedulerException, ParseException &#123;</div><div class="line">		Scheduler sched = sf.getScheduler();</div><div class="line">		Trigger trigger = sched.getTrigger(triggerName, triggerGroupName);</div><div class="line">		if (trigger != null) &#123;</div><div class="line">			CronTrigger ct = (CronTrigger) trigger;</div><div class="line">			// 修改时间</div><div class="line">			ct.setCronExpression(time);</div><div class="line">			// 重启触发器</div><div class="line">			sched.resumeTrigger(triggerName, triggerGroupName);</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 移除一个任务(使用默认的任务组名，触发器名，触发器组名)</div><div class="line">	 */</div><div class="line">	public static void removeJob(String jobName) throws SchedulerException &#123;</div><div class="line">		Scheduler sched = sf.getScheduler();</div><div class="line">		sched.pauseTrigger(jobName, TRIGGER_GROUP_NAME);// 停止触发器</div><div class="line">		sched.unscheduleJob(jobName, TRIGGER_GROUP_NAME);// 移除触发器</div><div class="line">		sched.deleteJob(jobName, JOB_GROUP_NAME);// 删除任务</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	/**</div><div class="line">	 * 移除一个任务</div><div class="line">	 */</div><div class="line">	public static void removeJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName)</div><div class="line">			throws SchedulerException &#123;</div><div class="line">		Scheduler sched = sf.getScheduler();</div><div class="line">		sched.pauseTrigger(triggerName, triggerGroupName);// 停止触发器</div><div class="line">		sched.unscheduleJob(triggerName, triggerGroupName);// 移除触发器</div><div class="line">		sched.deleteJob(jobName, jobGroupName);// 删除任务</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li>测试函数</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div></pre></td><td class="code"><pre><div class="line">package quartz;</div><div class="line"></div><div class="line">import java.text.SimpleDateFormat;</div><div class="line">import java.util.Date;</div><div class="line"></div><div class="line">public class QuartzTest &#123;</div><div class="line"></div><div class="line">	public static void main(String[] args) &#123;</div><div class="line">		SimpleDateFormat DateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd HH:mm:ss&quot;);</div><div class="line">		Date d = new Date();</div><div class="line">		String returnstr = DateFormat.format(d);</div><div class="line"></div><div class="line">		TestJob job = new TestJob();</div><div class="line">		String job_name = &quot;11&quot;;</div><div class="line">		try &#123;</div><div class="line">			// 每2秒钟执行一次</div><div class="line">			System.out.println(returnstr + &quot;【系统启动】&quot;);</div><div class="line">			QuartzManager.addJob(job_name, job, &quot;0/2 * * * * ?&quot;);</div><div class="line">			Thread.sleep(10 * 1000);</div><div class="line"></div><div class="line">			// 更改任务设置，好像不起作用，可以移除再添加一个任务</div><div class="line">			System.out.println(returnstr + &quot;【修改时间】&quot;);</div><div class="line">			QuartzManager.modifyJobTime(job_name, &quot;0/5 * * * * ?&quot;);</div><div class="line">			Thread.sleep(10 * 1000);</div><div class="line"></div><div class="line">			// 移除任务</div><div class="line">			System.out.println(returnstr + &quot;【移除定时任务】&quot;);</div><div class="line">			QuartzManager.removeJob(job_name);</div><div class="line">			Thread.sleep(10 * 1000);</div><div class="line"></div><div class="line">			// 添加任务</div><div class="line">			System.out.println(returnstr + &quot;【添加定时任务】&quot;);</div><div class="line">			QuartzManager.addJob(job_name, job, &quot;0/5 * * * * ?&quot;);</div><div class="line"></div><div class="line">		&#125; catch (Exception e) &#123;</div><div class="line">			e.printStackTrace();</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="Sitemesh"><a href="#Sitemesh" class="headerlink" title="Sitemesh"></a>Sitemesh</h2><hr>
<h3 id="sitemesh简介"><a href="#sitemesh简介" class="headerlink" title="sitemesh简介"></a>sitemesh简介</h3><p>将url请求进行过滤，使用配置的界面进行渲染。</p>
<h3 id="配置-1"><a href="#配置-1" class="headerlink" title="配置"></a>配置</h3><ul>
<li>SiteMesh 是一个网页布局和修饰的框架，利用它可以将网页的内容和页面结构分离，以达到页面结构共享的目的。</li>
<li>web.xml中配置filter，由于按filter按先后顺序执行，所以更小的filter放在前面。比如sitemesh-filter放在jfinal-filter之前。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&lt;filter&gt;</div><div class="line">	&lt;filter-name&gt;sitemesh&lt;/filter-name&gt;</div><div class="line">	&lt;filter-class&gt;org.sitemesh.config.ConfigurableSiteMeshFilter&lt;/filter-class&gt;</div><div class="line">&lt;/filter&gt;</div><div class="line">&lt;filter-mapping&gt;</div><div class="line">	&lt;filter-name&gt;sitemesh&lt;/filter-name&gt;</div><div class="line">	&lt;url-pattern&gt;/*&lt;/url-pattern&gt;</div><div class="line">&lt;/filter-mapping&gt;</div></pre></td></tr></table></figure>
<ul>
<li>sitemesh3.xml中配置模板路径等信息。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</div><div class="line">&lt;sitemesh&gt;</div><div class="line">	</div><div class="line">	&lt;content-processor&gt;</div><div class="line">     &lt;tag-rule-bundle class=&quot;com.usercenter.tools.sitemesh.MyTagRuleBundle&quot; /&gt;</div><div class="line">   &lt;/content-processor&gt;</div><div class="line">   </div><div class="line">	&lt;!-- 指明满足/*的页面被指定的模板装饰 --&gt;</div><div class="line">	&lt;mapping path=&quot;/to*&quot; decorator=&quot;/WEB-INF/views/commonpages/model.jsp&quot; /&gt;</div><div class="line">	</div><div class="line">	&lt;!-- 指明满足排除条件的页面不被装饰 --&gt;</div><div class="line">	&lt;!-- &lt;mapping path=&quot;/statics/*&quot; exclude=&quot;true&quot; /&gt; --&gt;</div><div class="line">&lt;/sitemesh&gt;</div></pre></td></tr></table></figure>
<h2 id="JDBC"><a href="#JDBC" class="headerlink" title="JDBC"></a>JDBC</h2><hr>
<p>JDBC是java为数据库操作提供的接口，具体实现由各数据库厂家决定。</p>
<h3 id="基础知识"><a href="#基础知识" class="headerlink" title="基础知识"></a>基础知识</h3><ul>
<li>驱动类名：对应相应的驱动jar包中的类路径。</li>
<li>驱动URL：协议、子协议、主机、端口、数据库等，如<code>jdbc:sqlserver://10.15.82.58:1433;DatabaseName=EngineeringMedicine</code></li>
<li>Statement/PreparedStatement/CallableStatement区别<ul>
<li>Statement最原始最普通，可查询、添加，查询容易被sql注入。</li>
<li>PreparedStatement预编译的sql，安全性比较高，本身使用set方法，对重复的查询高效。</li>
<li>CallableStatement调用存储过程。存储过程是数据库底层实现并优化的一系列数据操作。</li>
</ul>
</li>
</ul>
<h3 id="JDBC使用"><a href="#JDBC使用" class="headerlink" title="JDBC使用"></a>JDBC使用</h3><h4 id="使用流程"><a href="#使用流程" class="headerlink" title="使用流程"></a>使用流程</h4><p>一般的步骤为：</p>
<ol>
<li>搭建环境：创建工程，导入数据库包，创建数据库。</li>
<li>编程，加载数据库驱动<ul>
<li>方式一：Class.forName(driver);</li>
<li>方式二：DriverManager.registerDriver(new com.mysql.jdbc.Driver());//不推荐，因为会加载两次driver。</li>
</ul>
</li>
<li>建立连接<br>Connection connection = DriverManager.getConnection(url, user, pwd);//JDBC操作核心</li>
<li>创建数据库操作对象，发送sql<br>Statement st = connection.createStatement();<br>ResultSet rs = st.executeUpdate(“insert into user1 (name) values(‘zhangsan’)”);</li>
<li>从代表结果集的ResultSet中取出数据等操作。</li>
<li>断开数据库连接，释放资源。statement.close();connection.close();</li>
</ol>
<h4 id="示例代码"><a href="#示例代码" class="headerlink" title="示例代码"></a>示例代码</h4><ul>
<li>Sql操作</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div></pre></td><td class="code"><pre><div class="line">public class MySQL &#123;</div><div class="line">	public static final void main(String[] args) throws Exception &#123;</div><div class="line">		/**类名 */</div><div class="line">		String driver = &quot;com.mysql.jdbc.Driver&quot;;</div><div class="line">		String url = &quot;jdbc:mysql://127.0.0.1:3306/mytest&quot;;// 主协议：子协议/ip：port/db</div><div class="line">		String user = &quot;root&quot;;</div><div class="line">		String pwd = &quot;1234&quot;;</div><div class="line">		Connection connection = null; //接口</div><div class="line">		Statement statement = null;</div><div class="line">		</div><div class="line">		try &#123;</div><div class="line">			/**连接配置 */</div><div class="line">			// 1 加载驱动类 </div><div class="line">			Class.forName(driver);</div><div class="line">			// 另一种方式如下，但不推荐，因为会加载两次driver</div><div class="line">			// DriverManager.registerDriver(new com.mysql.jdbc.Driver());</div><div class="line">			</div><div class="line">			// 2 获取连接</div><div class="line">			connection = DriverManager.getConnection(url, user, pwd);</div><div class="line">			// 3 通过statement向数据库发出sql指令</div><div class="line">			//statement = connection.createStatement();//createStatement()不支持游标向后（向上）</div><div class="line">			statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);</div><div class="line">			</div><div class="line">			int n = statement.executeUpdate(&quot;insert into user1 (name) values(&apos;zhangsan&apos;)&quot;);//此方法进行增改删CRUD之cud</div><div class="line">			System.out.println(n + &quot;行已添加到：&quot; + connection);//输出connection可以查看数据库连接信息</div><div class="line">			</div><div class="line">			/**事务自动提交设置 */</div><div class="line">			connection.setAutoCommit(false);//默认是自动提交</div><div class="line">			connection.commit();</div><div class="line">			</div><div class="line">			/**ResultSet */</div><div class="line">			ResultSet resultSet = statement.executeQuery(&quot;select * from user1&quot;);//此方法进行查create,retrive,update,del </div><div class="line">			while(resultSet.next())&#123;//数据最后的next返回false</div><div class="line">				System.out.println(resultSet.getInt(1) + resultSet.getString(&quot;name&quot;));//游标所指数据</div><div class="line">			&#125;</div><div class="line">			resultSet.beforeFirst();//重新使用resultSet游标，回到第一行</div><div class="line">			System.out.println(&quot;重新使用游标&quot;);</div><div class="line">			while(resultSet.next())&#123;//数据最后的next返回false</div><div class="line">				System.out.println(resultSet.getInt(1) + resultSet.getString(&quot;name&quot;));//游标所指数据</div><div class="line">			&#125;</div><div class="line">			System.out.println(&quot;resultSet的其他方法&quot;);</div><div class="line">			resultSet.beforeFirst();//最前面的前面</div><div class="line">			resultSet.afterLast();//最后面的后面</div><div class="line">			resultSet.last();//定位到最后</div><div class="line">			resultSet.previous();</div><div class="line">			resultSet.absolute(2);//定位到第2行</div><div class="line">			System.out.println(resultSet.getString(&quot;id&quot;));</div><div class="line">			</div><div class="line">		&#125; catch (Exception e) &#123;</div><div class="line">			e.printStackTrace();</div><div class="line">			connection.rollback();//不是自动提交的时候，commit之前的出错可以回滚</div><div class="line">		&#125; finally &#123;</div><div class="line">			if (statement != null) &#123;</div><div class="line">				try &#123;</div><div class="line">					statement.close();</div><div class="line">				&#125; catch (SQLException e) &#123;</div><div class="line">					e.printStackTrace();</div><div class="line">				&#125;</div><div class="line">				statement = null; // 使用垃圾回收机制</div><div class="line">			&#125;</div><div class="line">			if (connection != null) &#123;</div><div class="line">				try &#123;</div><div class="line">					connection.close();</div><div class="line">				&#125; catch (SQLException e) &#123;</div><div class="line">					e.printStackTrace();</div><div class="line">				&#125;</div><div class="line">				connection = null;</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li>SqlHelper/DbUtil<br>由于数据库操作较多，所以可以进行封装。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line">public class DbUtil &#123;</div><div class="line">	/**如果并发量比较多就不能设置成static*/</div><div class="line">	private static Connection connection = null;</div><div class="line">	private static Statement statement= null;</div><div class="line">	private static ResultSet resultSet = null;</div><div class="line">	</div><div class="line">	/**数据库参数*/</div><div class="line">	private static String url;</div><div class="line">	private static String userName;</div><div class="line">	private static String driver;</div><div class="line">	private static String passwd;</div><div class="line">	private static Properties properties;</div><div class="line">	private static FileInputStream fileInputStream;</div><div class="line">	</div><div class="line">	//加载驱动，只需一次</div><div class="line">	static&#123;</div><div class="line">		try &#123;</div><div class="line">			//读取数据库配置文件</div><div class="line">			fileInputStream = new FileInputStream(&quot;src/main/resources/jdbc.properties&quot;);</div><div class="line">			properties = new Properties();//实例化</div><div class="line">			properties.load(fileInputStream);</div><div class="line">			</div><div class="line">			url = properties.getProperty(&quot;url&quot;);</div><div class="line">			userName = properties.getProperty(&quot;userName&quot;);</div><div class="line">			driver = properties.getProperty(&quot;driver&quot;);</div><div class="line">			passwd = properties.getProperty(&quot;passwd&quot;);</div><div class="line">			</div><div class="line">			Class.forName(driver);//加载驱动类</div><div class="line">		&#125; catch (Exception e) &#123;</div><div class="line">			e.printStackTrace();</div><div class="line">			//加载失败，可以退出程序了</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">	</div><div class="line">	public static Connection getConnection() throws Exception&#123;</div><div class="line">		connection = DriverManager.getConnection(url, userName, passwd);</div><div class="line">		return connection;</div><div class="line">	&#125;</div><div class="line">	</div><div class="line">	/**</div><div class="line">	 * 测试入口</div><div class="line">	 * @param args</div><div class="line">	 * @throws Exception</div><div class="line">	 */</div><div class="line">	public static void main(String[] args) throws Exception &#123;</div><div class="line">		System.out.println(DbUtil.getConnection());</div><div class="line">	&#125;</div><div class="line">	</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li>PreparedStatement<br>PreparedStatement采用字段名与？传参的方式，可以防止sql注入。如在statement中添加“or 1=1”的方式，所以一般不用statement。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">PreparedStatement ps = null;</div><div class="line">ps = connection.prepareStatement(&quot;select * from user1 where id = ? and name = ?&quot;);</div><div class="line">ps.setInt(1, 1);	//从1开始</div><div class="line">ps.setString(2, &quot;zhangsan&quot;);</div><div class="line">ResultSet resultSet = ps.executeQuery();</div></pre></td></tr></table></figure>
<h3 id="Sql注入"><a href="#Sql注入" class="headerlink" title="Sql注入"></a>Sql注入</h3><h4 id="基本概念"><a href="#基本概念" class="headerlink" title="基本概念"></a>基本概念</h4><ul>
<li>Sql注入漏洞是因为系统对传递到后台数据库的参数限制存在漏洞，导致可以通过设计特定的语句获取到超出设计预期的数据库权限。</li>
<li>例如：后台实现如果是select * from user where name= str，设计初衷是只能选取一个用户，但如果被用户输入str的值为 “a” or 1=1，则会输出所有数据。</li>
</ul>
<h4 id="防止sql注入"><a href="#防止sql注入" class="headerlink" title="防止sql注入"></a>防止sql注入</h4><ul>
<li><strong>使用安全的sql封装语句或框架</strong>：一些封装的语句或框架会将参数作为一个整体，不会对参数内部进行解析成sql条件，如jdbc的preparedStatement类、mybatis的#{para}等。</li>
<li><strong>参数过滤</strong>：一般sql注入的语句会很长很复杂，可以限定参数长度并且禁止含有*、%特殊字符。</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java-web/" rel="tag">#Java web</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/01/12/Software/Java Web/JFinal/" rel="next" title="JFinal">
                <i class="fa fa-chevron-left"></i> JFinal
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/12/Software/Java Web/Log4j/" rel="prev" title="Log4j">
                Log4j <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    


  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/statics/images/avatar.png"
               alt="gatewayzy" />
          <p class="site-author-name" itemprop="name">gatewayzy</p>
          <p class="site-description motion-element" itemprop="description">blog website with hexo and github pages</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/gatewayzy" title="Github-gatewayzy" target="_blank">Github-gatewayzy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://google.com/" title="Goolge" target="_blank">Goolge</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wiki.jikexueyuan.com/" title="Wiki-jike" target="_blank">Wiki-jike</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Ajax跨域请求允许"><span class="nav-number">1.</span> <span class="nav-text">Ajax跨域请求允许</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#修改被请求网站响应设置"><span class="nav-number">1.1.</span> <span class="nav-text">修改被请求网站响应设置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#中文分词工具"><span class="nav-number">2.</span> <span class="nav-text">中文分词工具</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#IKAnalyzer与Lucene"><span class="nav-number">2.1.</span> <span class="nav-text">IKAnalyzer与Lucene</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IKAnalyzer特点"><span class="nav-number">2.2.</span> <span class="nav-text">IKAnalyzer特点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置"><span class="nav-number">2.3.</span> <span class="nav-text">配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置demo"><span class="nav-number">2.4.</span> <span class="nav-text">配置demo</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Quartz-定时任务"><span class="nav-number">3.</span> <span class="nav-text">Quartz 定时任务</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Sitemesh"><span class="nav-number">4.</span> <span class="nav-text">Sitemesh</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#sitemesh简介"><span class="nav-number">4.1.</span> <span class="nav-text">sitemesh简介</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置-1"><span class="nav-number">4.2.</span> <span class="nav-text">配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JDBC"><span class="nav-number">5.</span> <span class="nav-text">JDBC</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#基础知识"><span class="nav-number">5.1.</span> <span class="nav-text">基础知识</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JDBC使用"><span class="nav-number">5.2.</span> <span class="nav-text">JDBC使用</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#使用流程"><span class="nav-number">5.2.1.</span> <span class="nav-text">使用流程</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#示例代码"><span class="nav-number">5.2.2.</span> <span class="nav-text">示例代码</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Sql注入"><span class="nav-number">5.3.</span> <span class="nav-text">Sql注入</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#基本概念"><span class="nav-number">5.3.1.</span> <span class="nav-text">基本概念</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#防止sql注入"><span class="nav-number">5.3.2.</span> <span class="nav-text">防止sql注入</span></a></li></ol></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">gatewayzy</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>
  <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>



  

  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
